package com.cskt.handler;

import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * 自定义处理器,可以定义处理登录失败后的处理逻辑
 *
 * @author admin
 * @date 2023/05/11 16:03
 **/
@Component
public class CustomHandler implements AuthenticationFailureHandler {

    @Override
    public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
//        登录失败后，直接重定向到登录页面
        response.sendRedirect("/toLoginPage");
    }
}
